package com.share.finance.risk.third.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.share.common.common.Page;
import com.share.finance.risk.third.mapper.ChannelRequestLogMapper;
import com.share.finance.risk.third.model.db.ChannelRequestLog;
import com.share.finance.risk.third.model.vo.ChannelLogPageReq;
import com.share.finance.risk.third.service.IChannelRequestLogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class ChannelRequestLogServiceImpl extends ServiceImpl<ChannelRequestLogMapper, ChannelRequestLog> implements IChannelRequestLogService {

    @Resource
    private ChannelRequestLogMapper channelRequestLogMapper;

    @Override
    public Page pageList(ChannelLogPageReq req) {
        PageHelper.startPage(req.getPageNum(), req.getPageSize());
        LambdaQueryWrapper<ChannelRequestLog> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(req.getName())) {
            queryWrapper.like(ChannelRequestLog::getName, req.getName());
        }
        if (StringUtils.isNotBlank(req.getCacheKey())) {
            queryWrapper.like(ChannelRequestLog::getCacheKey, req.getCacheKey());
        }
        if (StringUtils.isNotBlank(req.getBankCard())) {
            queryWrapper.like(ChannelRequestLog::getBankCard, req.getBankCard());
        }
        if (StringUtils.isNotBlank(req.getPhoneNo())) {
            queryWrapper.like(ChannelRequestLog::getPhoneNo, req.getPhoneNo());
        }
        if (StringUtils.isNotBlank(req.getProductCode())) {
            queryWrapper.like(ChannelRequestLog::getProductCode, req.getProductCode());
        }
        if (StringUtils.isNotBlank(req.getIntId())) {
            queryWrapper.like(ChannelRequestLog::getIntId, req.getIntId());
        }
        if (StringUtils.isNotBlank(req.getSessionId())) {
            queryWrapper.like(ChannelRequestLog::getSessionId, req.getSessionId());
        }
        queryWrapper.orderByDesc(ChannelRequestLog::getId);
        List<ChannelRequestLog> list = channelRequestLogMapper.selectList(queryWrapper);
        return new Page<>(list, new PageInfo<>(list).getTotal(), req);
    }
}
